from sqlalchemy import Column, Integer, String, func, DateTime, JSON, Boolean, ForeignKey, Enum, Float
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
from sqlalchemy.orm import relationship

from models import Base
from utils import check_or_enum


class CaseInterfaceList(Base):
    """用例接口列表"""
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    name = Column(String(100), unique=True, nullable=False, comment="接口用例名称")
    description = Column(String(1000), comment="接口用例描述")
    requestMethod = Column(Enum('get', 'post', 'put', 'delete'), nullable=False,
                           comment="接口请求方法")
    route = Column(String(1000), comment="接口请求地址")
    createName = Column(String(20), comment="创建者")
    updateName = Column(String(20), comment="最后更新人")
    testResult = Column(JSON, comment="测试结果")
    status = Column(Boolean, comment="用例接口列表状态")
    requestProtocol = Column(Enum('http', "https"), nullable=False, comment="请求协议")
    domain = Column(String(100), comment="主域名")
    isClearCookie = Column(Boolean, comment="是否清除Cookie")
    headers = Column(JSON, comment="请求头")
    requestParams = Column(String(18000), comment="请求参数")
    setGlobalVars = Column(JSON, comment="返回结果设置全局变量")
    checkHttpCode = Column(String(10), comment="HTTP状态校验")
    checkResponseTime = Column(Float(10), comment="接口耗时校验")
    checkResponseData = Column(JSON, comment="JSON正则校验")

    projectId = Column(Integer, ForeignKey('project.id', ondelete="CASCADE"), nullable=False, comment="项目ID")
    caseListId = Column(Integer, ForeignKey('caselist.id', ondelete="CASCADE"), nullable=False, comment="用例列表ID")
